﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Sys.App.Structure.controls
{
    public partial class insert : UserControl
    {
        public insert()
        {
            InitializeComponent();
            this.Loaded += (obj, e) =>
            {
                OnLoad();
            };

        }

        public JuCloudy.Data.Entity.SysStructure Entity { get; set; }

        public JuCloudy.Sys.App.Structure.MainPage Mainpage { get; set; }

        private void OnLoad()
        {
            if (this.Entity != null)
            {
                txt_name.Text = Entity.StructureHeader;
                txt_order.Text = Entity.StructureOrder.ToString();
                chk_visable.IsChecked = Entity.IsVisable;
            }

            btn_submit.Click += (obj, e) =>
            {
                if (String.IsNullOrEmpty(this.txt_order.Text) ||
                    String.IsNullOrEmpty(this.txt_name.Text) ||
                     this.chk_visable.IsChecked == null)
                {
                    MessageBox.Show("表单不能为空！");
                    return;
                }

                var model = new Data.Entity.SysStructure()
                {
                    IsVisable = (bool)this.chk_visable.IsChecked,
                    StructureHeader = this.txt_name.Text,
                    StructureOrder = int.Parse(this.txt_order.Text)
                };

                if (this.Entity != null)
                    model.StructureId = Entity.StructureId;

                Mainpage.insert(model);
            };
        }
    }
}
